#include<bits/stdc++.h>
using namespace std;
map<int,int> mp;
int n;
int a[200005];
long long dfs(int zb,int red,int blue){
    if(zb>n){
        long long fs=0;
        return fs;
    }
    int aa=0,bb=0;
    if(a[zb]==a[red]){
        aa=a[zb];
    }
    if(a[zb]==a[blue]){
        bb=a[zb];
    }
    return max(aa+dfs(zb+1,zb,blue),bb+dfs(zb+1,red,zb));
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;
    scanf("%d",&T);
    while(T--){
        scanf("%d",&n);
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
        }
        long long ans=dfs(2,1,0);
        printf("%lld\n",ans);
    }
    return 0;
}
